package com.tanhua;

import cn.hutool.core.io.FileUtil;
import com.github.tobato.fastdfs.domain.conn.FdfsWebServer;
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

@RunWith(SpringRunner.class)
@SpringBootTest
public class FastDfsDemo {

    @Autowired
    private FastFileStorageClient client;  //客户端

    @Autowired
    private FdfsWebServer webServer; //nginx的代理对象

    @Test
    public void test1() throws FileNotFoundException {
        // 指定资源
        File file=new File("C:\\Users\\muzimoo\\Desktop\\图片\\1576134125940400.mp4");
        FileInputStream is = new FileInputStream(file);

        // 客户端对象上传
                // 参数1：文件流
                // 参数2：文件大小
                // 参数2：文件后缀名
                // 参数2：文件属性（null）
        StorePath storePath = client.uploadFile(is, file.length(), FileUtil.extName(file), null);
        String fullPath=webServer.getWebServerUrl()+storePath.getFullPath();
        System.out.println(fullPath);
    }

}
